﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace Alfa.Common.ValueConverters {
	/// <summary>
	/// Value converter that translates true to false and vice versa.
	/// </summary>
	public sealed class BooleanNegationConverter : IValueConverter {
		/// <summary>
		/// Converts true to false, false to true
		/// </summary>
		/// <param name="value">Value to convert. Should be bool.</param>
		/// <param name="targetType"></param>
		/// <param name="parameter"></param>
		/// <param name="culture"></param>
		/// <returns>Converted value (bool)</returns>
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
			return !(value is bool && (bool)value);
		}

		/// <summary>
		/// Converts back false to true, true to false
		/// </summary>
		/// <param name="value">Value to convert. Should be bool.</param>
		/// <param name="targetType"></param>
		/// <param name="parameter"></param>
		/// <param name="culture"></param>
		/// <returns>Converted value (bool)</returns>
		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
			return !(value is bool && (bool)value);
		}
	}
}
